<template>
  <div class="CommodityDetailsPage">
    <div class="CommodityDetailsPageHeader">
      <div class="CommodityDetailsPageHeader-title">
        <div class="CommodityDetailsPageHeader-title-L"></div>
        <div class="CommodityDetailsPageHeader-title-R">
          <div>沃尔玛-新街口店</div>
          <p>达达专送·60分钟</p>
          <p>基础运费¥4</p>
          <i></i>
          <i></i>
        </div>
      </div>
      <!-- 返利 -->
      <div class="rebate">
        <span class="rebateNode">返礼</span>
        <span class="rebateNode2">下单送砍价神刀，参与砍价最高可砍50%</span>
        <span class="rebateNode3">
          31种优惠
          <i></i>
        </span>
      </div>
    </div>
    <!-- 搜索框 -->
    <div class="searchInput">
      <div class="searchInputT">
        <div class="searchInputNode">
          <i></i>搜索店内商品，共3787件好物
        </div>
        <div class="searchInputIcon"></div>
      </div>
      <div class="TabbarNavs">
        <span>首页</span>
        <span class="TabbarNavsTitle">全部商品</span>
        <span>减运专区</span>
      </div>
    </div>
    <!-- 列表 -->
    <div class="ListOfSpecies">
      <div class="ListOfSpeciesTitle">
        <span v-for="{id,title} in ListOfSpeciesTitle" :key="id">{{title}}</span>
      </div>
      <div class="ListOfSpeciesR">
        <div class="ListOfSpeciesR-T">
          <span class="ListOfSpeciesR-N1">秒杀(129)</span>
          <span class="ListOfSpeciesR-N2">
            默认排序
            <i></i>
          </span>
        </div>
        <!-- 详情购买 -->
        <div class="PurchaseDetails">
          <div class="PurchaseDetailsImage"></div>
          <div class="PurchaseDetailsNodes" v-for="pd in PurchaseDetailsNodes" :key="pd.id">
            <div class="PurchaseDetailsNodes-L">
              <img :src="pd.imgUrl" />
            </div>
            <div class="PurchaseDetailsNodes-R">
              <div class="PurchaseDetailsNodes-N">{{pd.title}}</div>
              <div class="PurchaseDetailsNodes-T">{{pd.title1}}</div>
              <div class="PurchaseDetailsNodes-T2">{{pd.title2}}</div>
              <div class="PurchaseDetailsPrice">
                <div class="PurchaseDetailsPrice_D">
                  <div class="PurchaseDetailsPrice_P">￥{{pd.price}}</div>
                  <div class="PurchaseDetailsPrice_P_N">
                    <del>￥{{pd.sprice}}</del>
                  </div>
                </div>
                <!-- 加减按钮 -->
                <div class="bth">
                  <span v-show="pd.num">
                    <button @click="sub(pd.id)"></button>
                    {{pd.num}}
                  </span>
                  <button @click="add(pd)"></button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="PriceFooter">
      <div class="PriceFooterCar" @click="dis">
        <span>{{carCount}}</span>
      </div>
      <div class="PriceFooterCarMoney">
        <span>￥{{carTotal.totalSprice}}</span>
        <span>已经减去￥{{carTotal.totalPrice-carTotal.totalSprice}}</span>
      </div>
      <div class="MoneySettlement">去结算</div>
    </div>
    <!-- 影藏 -->
    <div class="MoneySettlementHidden" v-show="card">
      <div class="MoneySettlementHiddenC">
        <div class="MoneySettlementHiddenCT">
          <div class="MoneySettlementHiddenCTL">
            <i></i>
            <span>全选</span>
          </div>
          <div class="MoneySettlementHiddenCTR">
            <span class="MoneySettlementHiddenImage"></span>
            <span class="MoneySettlementHiddenCarclean" @click="empty">清空购物车</span>
          </div>
        </div>
        <div class="MoneySettlementHiddenContent" v-for="c in car" :key="c.id">
          <div class="MoneySettlementHiddenContentImg">
            <i></i>
          </div>
          <div class="MoneySettlementHiddenItems">
            <div class="MoneySettlementHiddenItems1">
              <img :src="c.imgUrl" />
            </div>
            <div class="MoneySettlementHiddenItems2">
              <div class="MoneySettlementHiddenItemsTitle1">{{c.title}}</div>
              <div class="MoneySettlementHiddenItemsTitle2">
                <div class="MoneySettlementHiddenPay">
                  <span class="MoneySettlementHiddentotality">￥{{c.sprice}}</span>
                  <span class="MoneySettlementHiddenskill">秒杀</span>
                </div>
                <div class="MoneySettlementHiddenButton">
                  <span v-show="c.num">
                    <button @click="sub(c.id)"></button>
                    {{c.num}}
                  </span>
                  <button @click="add(c)"></button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      car: {},
      ListOfSpeciesTitle: [],
      PurchaseDetailsNodes: [],
      card: false,
    };
  },
  computed: {
    carCount() {
      return Object.keys(this.car).length;
    },
    carTotal() {
      let totalPrice = 0;
      let totalSprice = 0;
      Object.values(this.car).forEach((el) => {
        totalPrice += el.price * el.num;
        totalSprice += el.sprice * el.num;
      });
      return {
        totalPrice,
        totalSprice,
      };
    },
  },
  created() {
    this.getListOfSpeciesTitle();
    this.getPurchaseDetailsNodes();
  },
  methods: {
    // 清空购物车
    empty() {
      Object.keys(this.car).forEach((el) => {
        this.car[el].num = 0;
        this.$delete(this.car, el);
      });
    },
    // 加号
    add(da) {
      const data = da;
      if (data.num) {
        if (data.num >= data.nums) {
          data.num = data.nums;
        } else {
          data.num += 1;
        }
      } else {
        this.$set(data, 'num', 1);
      }
      this.$set(this.car, data.id, data);
    },
    // 减号
    sub(id) {
      this.car[id].num -= 1;
      if (this.car[id].num <= 0) {
        this.$delete(this.car, id);
      }
    },
    // 点击 弹出框
    dis() {
      this.card = !this.card;
    },
    async getListOfSpeciesTitle() {
      const {
        data: { data },
      } = await this.api.getListOfSpeciesTitle();
      this.ListOfSpeciesTitle = data;
    },
    async getPurchaseDetailsNodes() {
      const {
        data: { data },
      } = await this.api.getPurchaseDetailsNodes();
      this.PurchaseDetailsNodes = data;
    },
  },
};
</script>

<style lang="scss" scoped>
.CommodityDetailsPage {
  .CommodityDetailsPageHeader {
    box-sizing: border-box;
    padding: 8px 10px 15px;
    height: 124px;
    .CommodityDetailsPageHeader-title {
      height: 70px;
      margin-bottom: 13px;
      display: flex;
      justify-content: space-between;
      .CommodityDetailsPageHeader-title-L {
        width: 68px;
        height: 68px;
        background: pink;
        background: url(../../public/uploads/5015d5f6a2eb1edc2.png) no-repeat;
        background-size: 100%;
      }
      .CommodityDetailsPageHeader-title-R {
        height: 70px;
        width: 277px;
        position: relative;
        > div {
          height: 30px;
          font-size: 18px;
          margin-bottom: 5px;
          font-weight: 700;
        }
        > p:nth-child(2) {
          font-size: 10px;
          margin-bottom: 9px;
        }
        > p:nth-child(3) {
          font-size: 10px;
        }
        > i:nth-child(4) {
          display: inline-block;
          width: 30px;
          height: 30px;
          background: url(../../public/uploads/focus.5662b820.png) no-repeat;
          background-size: 68px auto;
          background-position: 3px 4px;
          position: absolute;
          right: 0;
          top: 0;
        }
        > i:nth-child(5) {
          display: inline-block;
          width: 68px;
          height: 38px;
          background: url(../../public/uploads/dac602f837996046.gif) no-repeat;
          background-size: 100%;
          position: absolute;
          right: 0;
          top: 35px;
        }
      }
    }
    .rebate {
      height: 15.2px;
      display: flex;
      .rebateNode {
        display: inline-block;
        background-image: linear-gradient(
          135deg,
          rgb(255, 125, 125) 0%,
          rgb(255, 81, 56) 100%
        );
        border-top-right-radius: 1px;
        border-top-left-radius: 4px;
        border-bottom-right-radius: 4px;
        border-bottom-left-radius: 1px;
        font-size: 11px;
        height: 14px;
        padding: 0 3px;
        margin-right: 5px;
        color: #fff;
      }
      .rebateNode2 {
        color: rgb(102, 102, 102);
        font-size: 11px;
        padding-right: 60px;
      }
      .rebateNode3 {
        font-size: 11px;
        color: rgb(102, 102, 102);
        > i {
          display: inline-block;
          border-right: 1px solid rgb(153, 153, 153);
          border-bottom: 1px solid rgb(153, 153, 153);
          height: 8px;
          transform: translateY(-3.25px) rotate(45deg);
          transform-origin: center center;
          width: 8px;
          margin-left: 5px;
        }
      }
    }
  }
  .searchInput {
    height: 79px;
    .searchInputT {
      height: 30px;
      padding: 5px 10px;
      display: flex;
      justify-content: space-between;
      .searchInputNode {
        width: 308px;
        height: 30px;
        background-color: #f4f4f4;
        border-radius: 30px;
        font-size: 14px;
        color: #999;
        text-align: center;
        line-height: 30px;
        position: relative;
        > i {
          display: inline-block;
          width: 22px;
          height: 22px;
          background: url(../../public/uploads/search_bar_sprites.57c20493.png) no-repeat;
          background-size: 44px auto;
          background-position: -5px -7px;
          position: absolute;
          top: 0px;
          left: 30px;
        }
      }
      .searchInputIcon {
        width: 47px;
        height: 30px;
        background: url(../../public/uploads/groupCopy.268ca879.png) no-repeat;
        background-size: 44px auto;
      }
    }
    .TabbarNavs {
      height: 39px;
      padding-left: 10px;
      > span {
        height: 17px;
        display: inline-block;
        text-align: center;
        color: #999;
        font-size: 18px;
        padding: 10px 0;
        margin-right: 30px;
      }
      .TabbarNavsTitle {
        color: #333;
        border-bottom: 2px solid #08c12a;
        font-weight: 600;
      }
    }
  }
  .ListOfSpecies {
    height: 584px;
    display: flex;
    .ListOfSpeciesTitle {
      width: 80px;
      height: 584px;
      overflow-y: scroll;
      > span {
        display: inline-block;
        height: 46px;
        padding: 2px 12px;
        line-height: 21px;
        width: 56px;
        color: #666;
        font-size: 14px;
        line-height: 46px;
        background: rgb(250, 250, 250);
      }
      > span:nth-child(1) {
        background: #fff;
        color: #333;
        font-weight: 700;
      }
    }
    .ListOfSpeciesR {
      height: 534px;
      width: 295px;
      position: relative;
      .ListOfSpeciesR-T {
        width: 295px;
        height: 30px;
        display: flex;
        justify-content: space-between;
        background: #fff;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 100;
        .ListOfSpeciesR-N1 {
          font-size: 12px;
          color: #666;
          line-height: 30px;
          margin-left: 5px;
        }
        .ListOfSpeciesR-N2 {
          font-size: 12px;
          color: #666;
          line-height: 30px;
          margin-right: 10px;
          > i {
            display: inline-block;
            border-right: 1px solid rgb(153, 153, 153);
            border-bottom: 1px solid rgb(153, 153, 153);
            height: 6px;
            transform: translateY(-3.25px) rotate(45deg);
            transform-origin: center center;
            width: 6px;
            margin-left: 5px;
          }
        }
      }
      .PurchaseDetails {
        height: 534px;
        width: 295px;
        overflow-y: scroll;
        .PurchaseDetailsImage {
          height: 30px;
        }
        .PurchaseDetailsNodes {
          margin-left: 10px;
          width: 265px;
          height: 114px;
          padding: 16px 10px 16px 10px;
          border-bottom: 1px solid rgb(245, 245, 245);
          display: flex;
          .PurchaseDetailsNodes-L {
            width: 80px;
            height: 80px;
            img {
              width: 100%;
            }
          }
          .PurchaseDetailsNodes-R {
            width: 177px;
            height: 111px;
            margin-left: 8px;
            .PurchaseDetailsNodes-N {
              font-size: 16px;
              font-weight: bold;
              line-height: 20px;
              color: rgb(51, 51, 51);
            }
            .PurchaseDetailsNodes-T {
              font-size: 11px;
              line-height: 14px;
              margin-top: 4px;
              color: rgb(102, 102, 102);
            }
            .PurchaseDetailsNodes-T2 {
              width: 55px;
              height: 14px;
              padding: 0 3px;
              font-size: 11px;
              line-height: 14px;
              margin-top: 8px;
              color: #fff;
              background-image: linear-gradient(
                135deg,
                rgb(255, 125, 125) 0%,
                rgb(255, 81, 56) 100%
              );
              border-top-right-radius: 1px;
              border-top-left-radius: 4px;
              border-bottom-right-radius: 4px;
              border-bottom-left-radius: 1px;
            }
            .PurchaseDetailsPrice {
              margin-top: 10px;
              height: 40px;
              display: flex;
              justify-content: space-between;
              align-items: center;
              .PurchaseDetailsPrice_D {
                width: 70px;
                height: 40px;
                .PurchaseDetailsPrice_P {
                  width: 70px;
                  height: 24px;
                  color: rgb(255, 30, 25);
                  font-size: 18px;
                  font-weight: bold;
                }
                .PurchaseDetailsPrice_P_N {
                  width: 70px;
                  height: 16px;
                  color: rgb(153, 153, 153);
                  font-size: 13px;
                }
              }
              .bth {
                width: 100px;
                height: 40px;
                text-align: right;
                display: flex;
                justify-content: space-around;
                align-items: center;
                > span {
                  display: inline-block;
                  width: 50px;
                  height: 40px;
                  display: flex;
                  align-items: center;
                }
                button:nth-child(1) {
                  width: 27px;
                  height: 27px;
                  background: url(../../public/uploads/op.455b25b1.png) no-repeat 0 -78px;
                  background-size: 100%;
                  border: none;
                  outline: none;
                  margin-right: 10px;
                }
                button:nth-child(2) {
                  width: 27px;
                  height: 27px;
                  background: url(../../public/uploads/op.455b25b1.png) no-repeat;
                  background-size: 100%;
                  border: none;
                  outline: none;
                }
              }
            }
          }
        }
      }
    }
  }
  .PriceFooter {
    width: 100%;
    height: 50px;
    position: fixed;
    bottom: 0px;
    left: 0px;
    z-index: 300;
    background: #fff;
    display: flex;
    justify-content: space-between;
    .PriceFooterCar {
      width: 50px;
      height: 50px;
      background: url(../../public/uploads/cart.192bbe87.png) no-repeat;
      background-size: 50px;
      background-position: 0 100%;
      margin-bottom: 5px;
      position: relative;
      > span {
        display: inline-block;
        width: 18px;
        height: 18px;
        background: rgb(255, 87, 87);
        border-radius: 9px;
        color: rgb(255, 255, 255);
        font-size: 11px;
        text-align: center;
        position: absolute;
        top: -10px;
        right: 3px;
      }
    }
    .PriceFooterCarMoney {
      width: 195px;
      height: 50px;
      line-height: 50px;
      > span:nth-child(1) {
        font-size: 22px;
        color: #ff3434;
        margin-right: 5px;
      }
      > span:nth-child(2) {
        font-size: 12px;
        color: #999;
        margin-left: 5px;
      }
    }
    .MoneySettlement {
      width: 110px;
      height: 50px;
      background: linear-gradient(90deg, #00be34, #00cb1e);
      color: rgb(255, 255, 255);
      font-size: 16px;
      font-weight: bold;
      text-align: center;
      line-height: 50px;
    }
  }
  .MoneySettlementHidden {
    width: 375px;
    height: 667px;
    background: rgba(0, 0, 0, 0.3);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
    .MoneySettlementHiddenC {
      width: 100%;
      height: 500px;
      background: #fff;
      border-radius: 15px 15px 0 0;
      position: absolute;
      bottom: 0px;
      left: 0;
      .MoneySettlementHiddenCT {
        width: 100%;
        height: 36px;
        display: flex;
        justify-content: space-between;
        .MoneySettlementHiddenCTL {
          padding-left: 10px;
          width: 230px;
          height: 36px;
          display: flex;
          align-items: center;
          > i {
            display: inline-block;
            height: 22px;
            width: 42px;
            background: url(../../public/uploads/下载.png) no-repeat;
            background-size: 22px 22px;
          }
          > span {
            font-size: 12px;
            color: #333;
          }
        }
        .MoneySettlementHiddenCTR {
          width: 130px;
          height: 36px;
          display: flex;
          align-items: center;
          .MoneySettlementHiddenImage {
            display: inline-block;
            width: 55px;
            height: 18px;
            background: url(../../public/uploads/coupon_icon.1260b9ce.png) no-repeat;
            background-size: 40px 18px;
          }
          .MoneySettlementHiddenCarclean {
            padding: 0 10px 0 5px;
            font-size: 12px;
            color: #999;
          }
        }
      }
      .MoneySettlementHiddenContent {
        width: 100%;
        height: 83px;
        display: flex;
        justify-content: space-between;
        border-top: 1px solid #f5f5f5;
        .MoneySettlementHiddenContentImg {
          width: 32px;
          height: 70px;
          line-height: 70px;
          padding-left: 10px;
          > i {
            display: inline-block;
            height: 22px;
            width: 42px;
            background: url(../../public/uploads/下载.png) no-repeat;
            background-size: 22px 22px;
          }
        }
        .MoneySettlementHiddenItems {
          width: 333px;
          height: 72px;
          display: flex;
          justify-content: space-between;
          padding-top: 10px;
          .MoneySettlementHiddenItems1 {
            width: 50px;
            height: 50px;
            img {
              width: 100%;
            }
          }
          .MoneySettlementHiddenItems2 {
            width: 263px;
            height: 62px;
            .MoneySettlementHiddenItemsTitle1 {
              height: 16.8px;
              line-height: 17px;
              font-size: 14px;
              color: #333;
              margin-bottom: 5px;
            }
            .MoneySettlementHiddenItemsTitle2 {
              height: 40px;
              width: 263px;
              display: flex;
              justify-content: space-between;
              .MoneySettlementHiddenPay {
                height: 40px;
                width: 100px;
                line-height: 40px;
                display: flex;
                flex-wrap: wrap-reverse;
                align-content: stretch;
                .MoneySettlementHiddenskill {
                  display: inline-block;
                  width: 32px;
                  height: 12px;
                  background-image: linear-gradient(
                    135deg,
                    rgb(255, 125, 125) 0%,
                    rgb(255, 81, 56) 100%
                  );
                  color: #fff;
                  font-size: 10px;
                  border-top-right-radius: 1px;
                  border-top-left-radius: 4px;
                  border-bottom-right-radius: 4px;
                  border-bottom-left-radius: 1px;
                  line-height: 12px;
                  text-align: center;
                }
                .MoneySettlementHiddentotality {
                  display: inline-block;
                  width: 90px;
                  height: 16.8px;
                  color: rgb(255, 87, 87);
                  font-size: 17px;
                  line-height: 17px;
                }
              }
              .MoneySettlementHiddenButton {
                height: 40px;
                width: 100px;
                text-align: center;
                display: flex;
                justify-content: space-around;
                align-items: center;
                > span {
                  display: flex;
                  align-items: center;
                }
                button:nth-child(1) {
                  width: 27px;
                  height: 27px;
                  background: url(../../public/uploads/op.455b25b1.png) no-repeat 0 -78px;
                  background-size: 100%;
                  border: none;
                  outline: none;
                  margin-right: 10px;
                }
                button:nth-child(2) {
                  width: 27px;
                  height: 27px;
                  background: url(../../public/uploads/op.455b25b1.png) no-repeat;
                  background-size: 100%;
                  border: none;
                  outline: none;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
